﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Omes.Services;

namespace FashionMural.Web
{
    public partial class ServerDetail : System.Web.UI.Page
    {
        private IResourceService resourceservice;
        private IPageService pageservice;
        public int FatherPageId { set; get; }
        public string HtmlText { set; get; }
        public Omes.Model.ImageList CurrentImage;
        public List<Omes.Model.ImageList> Images { set; get; }
        public int CurrentIndex { set; get; }
        public int NextId { get; set; }
        public int PreId { set; get; }
        public string NaUrl { set; get; }
        public List<Omes.Model.Page> ChildPages { set; get; }
        public Omes.Model.Page CurrentPage { set; get; }
        public List<Omes.Model.NewsList> News { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            resourceservice = new ResourceService();
            pageservice = new PageService();
            var pageidstr = HttpContext.Current.Request.Params["f"];
            var itemstr = HttpContext.Current.Request.Params["t"];
            //link img
            var fromtype = HttpContext.Current.Request.Params["ct"];
            NaUrl = "/ProjuctDetail.aspx?f=" + pageidstr + "&t={0}&ct=" + fromtype;
            var ppid = int.Parse(pageidstr);
            CurrentPage = pageservice.GetPage(ppid);
            ChildPages = pageservice.GetChildPage(CurrentPage.ParentId);
            int nid = int.Parse(System.Configuration.ConfigurationManager.AppSettings["xwzx"]);
            News = resourceservice.GetNews(nid, commend: 1).Lists;
            int itemid = 0;
            int pageid = 0;
            if (fromtype == "img")
            {
                imgdetailph.Visible = true;

                if (int.TryParse(itemstr, out itemid) && int.TryParse(pageidstr, out pageid))
                {
                    FatherPageId = pageid;
                    //获取所有图片列表
                    Images = resourceservice.GetImages(FatherPageId).Images;
                    CurrentIndex = Images.FindIndex(i => i.Id == itemid);
                    CurrentImage = resourceservice.GetImageByid(itemid);
                    try
                    {
                        PreId = Images[CurrentIndex - 1].Id;
                    }
                    catch { }
                    try
                    {
                        NextId = Images[CurrentIndex + 1].Id;
                    }
                    catch { }
                }
            }
            else if (fromtype == "link")
            {
                linkdetailph.Visible = true;
                if (int.TryParse(itemstr, out itemid) && int.TryParse(pageidstr, out pageid))
                {
                    FatherPageId = pageid;
                    HtmlText = resourceservice.GetLinkByid(itemid).Content;
                }
            }
        }
    }
}